//
//  NetRequest+UserAPI.m
//  AppleMarket
//
//  Created by yangy on 23/10/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "NetRequest+UserAPI.h"

@implementation NetRequest (UserAPI)


+ (void) request_DoLoginWithAccount:(NSString*) account
                           password:(NSString*) password
                          imageCode:(NSString*) imageCode
                       imageCodeKey:(NSString*) codeKey
                    completeHandler:(void (^)(id responseObj)) completeHandler
                               fail:(void (^)(NSError *error)) failHandler
{
    NSDictionary *parameters = @{
                                 @"Account" : account,
                                 @"AreaCode" : @"86",
                                // @"VerifyCode" : kObjectIsEmpty(verifyCode)? @"" : verifyCode,
                                 @"LoginPwd" : password,
                                 @"ImgCode" : imageCode,
                                 @"ImageCodeKey" : codeKey
                                 };
    [self postWithUrl:@"/api/UserApi/DoLogin" parameters:parameters success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO includeParameterToURL:NO];
}

+ (void) request_CheckForAccount:(NSString*) acoount
                 completeHandler:(void (^)(id responseObj)) completeHandler
                            fail:(void (^)(NSError *error)) failHandler
{
    NSDictionary *parameters = @{
                                 @"account" : acoount
                                     };
    [self getWithUrl:@"/api/UserApi/CheckAccount" parameters:parameters success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO];
}

+ (void) request_loginStrategy:(NSString*) account
               completeHandler:(void (^)(id responseObj)) completeHandler
                          fail:(void (^)(NSError *error)) failHandler
{
    NSDictionary *parameters = @{
                                 @"Account" : account,
                                 @"AreaCode" : @(86)
                                 };
    [self getWithUrl:@"/api/UserApi/GetLoginStrategy" parameters:parameters success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO];
}

+ (void) request_registerAccount:(NSString*) account
                      verifyCode:(NSString*) vCode
                           agree:(BOOL) agree
                        password:(NSString*) pwd
                         imgCode:(NSString*) imgCode
                          imgKey:(NSString*) key
                 completeHandler:(void (^)(id responseObj)) completeHandler
                            fail:(void (^)(NSError *error)) failHandler{
    NSDictionary *parameters = @{
                                 @"Account" : account,
                                 @"AreaCode" : @(86),
                                 @"VerifyCode" : vCode,
                                 @"LoginPwd" : pwd,
                                 @"ImgCode" : imgCode,
                                 @"ImageCodeKey" : key,
                                 @"Agreement" : @(agree)
                                 };
    [self postWithUrl:@"/api/UserApi/DoSignup" parameters:parameters success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO includeParameterToURL:NO];
}

+ (void) request_forgetAccount:(NSString*) account
                    verifyCode:(NSString*) vCode
                      password:(NSString*) pwd
                       imgCode:(NSString*) imgCode
                        imgKey:(NSString*) key
               completeHandler:(void (^)(id responseObj)) completeHandler
                          fail:(void (^)(NSError *error)) failHandler
{
    NSDictionary *parameters = @{
                                 @"Account" : account,
                                 @"AreaCode" : @(86),
                                 @"VerifyCode" : vCode,
                                 @"LoginPwd" : pwd,
                                 @"ImgCode" : imgCode,
                                 @"ImageCodeKey" : key
                                 };
    [self postWithUrl:@"/api/UserApi/DoForgotLoginPwd" parameters:parameters success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO includeParameterToURL:NO];
}

+ (void) request_loginoutWithCompleteHandler:(void (^)(id responseObj)) completeHandler
                                        fail:(void (^)(NSError *error)) failHandler
{
    [self postWithUrl:@"/api/UserApi/Logout" parameters:nil success:^(id response) {
        completeHandler(response);
    } fail:^(NSError *error) {
        failHandler(error);
    } showHUD:NO includeParameterToURL:NO];
}

@end
